package com.itboye.jinpuyiyuan.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.itboye.jinpuyiyuan.R;
import com.itboye.jinpuyiyuan.bean.DoctorRegInfoBean;
import com.itboye.jinpuyiyuan.bean.QueryDoctorListBean;
import com.itboye.jinpuyiyuan.bean.QueryDoctorListBeanNew;
import com.itboye.jinpuyiyuan.utils.sputil.Const;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/12/9 0009.
 */

public class NewRegisterDoctorDetailAdapter extends BaseAdapter {
    private ArrayList<DoctorRegInfoBean> list;
    private Context context;
    private LayoutInflater inflater;

    public NewRegisterDoctorDetailAdapter(Context context, ArrayList<DoctorRegInfoBean> list){
        this.list=list;
        this.context=context;
        inflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      String strenth="";
      RegisterDoctorDetailHolder registerDoctorDetailHolder;
        if (convertView==null){
            registerDoctorDetailHolder=new RegisterDoctorDetailHolder();
            convertView=inflater.inflate(R.layout.item_registerdoctorlist,parent,false);
            registerDoctorDetailHolder.doctorName=convertView.findViewById(R.id.doctorName);
//            registerDoctorDetailHolder.doctorProvince=convertView.findViewById(R.id.doctorProvince);
//            registerDoctorDetailHolder.doctorCity=convertView.findViewById(R.id.doctorCity);
            registerDoctorDetailHolder.doctorEvaluate=convertView.findViewById(R.id.doctorEvaluate);
//            registerDoctorDetailHolder.doctorStrengths=convertView.findViewById(R.id.doctorStrengths);
            registerDoctorDetailHolder.tvRegister=convertView.findViewById(R.id.tvRegister);
            registerDoctorDetailHolder.doctorImg=convertView.findViewById(R.id.doctorImg);
            convertView.setTag(registerDoctorDetailHolder);
        }else {
            registerDoctorDetailHolder= (RegisterDoctorDetailHolder) convertView.getTag();
        }

        if (list.size()>0){
            registerDoctorDetailHolder.doctorName.setText(list.get(position).getName()==null?"" :list.get(position).getName());
            registerDoctorDetailHolder.doctorEvaluate.setText(list.get(position).getJob_title()==null?"":list.get(position).getJob_title());
//        registerDoctorDetailHolder.doctorEvaluate.setText(list.get(position).getDt_level_name());
//        registerDoctorDetailHolder.doctorCity.setText(list.get(position).getCity());
//        for (int i=0;i<list.get(position).getSect_list().size();i++){
//            strenth+=list.get(position).getSect_list().get(i).getCname();
//            if (i!=(list.get(position).getSect_list().size()-1)){
//               strenth+=" , ";
//            }
//        }
//        registerDoctorDetailHolder.doctorStrengths.setText(strenth);
//        registerDoctorDetailHolder.doctorProvince.setText(list.get(position).getProvince());
//        Log.d("==========",list.get(position).getRealname()+"=="+list.get(position).getDt_level_name()+"=="+list.get(position).getCity()+"==");
            if (list.get(position).getReg_list()!=null){
                if (list.get(position).getReg_list().get(0).getReg_time_list().size()<=0){
                    registerDoctorDetailHolder.tvRegister.setText("挂号结束");
                }else {
                    for (int j=0;j<list.get(position).getReg_list().get(0).getReg_time_list().size();j++){
                        DoctorRegInfoBean.RegTime.ItemRegTime itemRegTime = list.get(position).getReg_list().get(0).getReg_time_list().get(j);
                        if (Integer.parseInt(itemRegTime.getOver_count().trim())>0){
                            registerDoctorDetailHolder.tvRegister.setText("挂号");
                        }
                    }
                }
            }else {
                registerDoctorDetailHolder.tvRegister.setText("挂号结束");
            }

            Glide.with(context).load(Const.DoctorImg+list.get(position).getUid()).into(registerDoctorDetailHolder.doctorImg);
        }

        return convertView;
    }

    class RegisterDoctorDetailHolder {
        TextView doctorName,
//                doctorProvince,
//                doctorCity,
                doctorEvaluate
//        ,doctorStrengths
        ,tvRegister;
        ImageView doctorImg;

    }

    public void addData(ArrayList<DoctorRegInfoBean> list){
        this.list=list;
        this.notifyDataSetChanged();
    }


}
